home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
034a
/
twview82.zip
/
MISC.INC
< prev
next >
Wrap
Text File
|
1991-02-04
|
3KB
|
108 lines
function die( size : integer ) : integer;
begin
die := random( size ) + 1;
end;
function prompt( p : string ) : boolean;
{ returns true if they say yes }
var
ch : char;
begin
write(p);
readln( ch );
prompt := ch in ['Y','y'];
end; {again}
function min( a, b : integer ) : integer;
begin
if a > b then
min := b
else
min := a;
end;
function minreal( a, b : real ) : real;
begin
if a > b then
minreal := b
else
minreal := a;
end; {minreal}
function IsWarp( from, OverTo : sector ) : boolean;
{ true if you can go from from to OverTo in one step }
var
t : warpIndex;
begin
IsWarp := false;
if space.sectors[ from ].number <> UnExplored then
for t := 1 to space.sectors[ from ].number do
if space.sectors[ from ].data[t] = OverTo then
IsWarp := true;
end; {IsWarp}
procedure FixDistances( sec : sector; var D : distanceArray );
{ D[j].d = distance from sec;
D[j].s = one node close }
var
s : sector;
breadth : queue;
daddy, sonny : sector;
i : warpindex;
begin
writeln('Computing distances...');
for s := 1 to maxSector do
D[s].d := -1;
breadth.front := 0;
enqueue( breadth, sec, sec );
while breadth.front > 0 do
begin
serve( breadth, daddy, sonny );
if D[ sonny ].d = -1 then {haven't hit him before:}
begin
D[ sonny ].d := D[ daddy ].d + 1;
D[ sonny ].s := daddy;
with space.sectors[ sonny ] do if number > 0 then
for i := 1 to number do
enqueue( breadth, sonny, data[ i ] );
end; {if}
end; {while}
for s := 1 to maxSector do if D[s].d = -1 then D[s].d := maxint;
end; {FixDistances}
function GetSector : SectorIndex;
var
s : integer;
begin
repeat
write('Sector? [0 to abort] ');
readln( s );
until (s>=0) and (s<=MaxSector);
GetSector := s;
end; {GetSector}
function LogToDisk( var f : text; message : string ) : boolean;
var
filename : string;
ch : char;
begin
if not prompt( message ) then
LogToDisk := false
else
begin
LogToDisk := true;
write('Name of file for log? ');
readln( filename );
assign( f, filename );
rewrite( f );
end; {else}
end; {LogToDisk}
function upcase( ch : char ) : char;
{ if letter in 'a'..'z' give upper case equivalent }
begin
if ch in ['a'..'z'] then
upcase := chr( ord( ch ) - ord('a') + ord('A') )
else
upcase := ch;
end; {upcase}